import 'package:flustars_flutter3/flustars_flutter3.dart';
import 'package:flutter/material.dart';

import '../../../../common/my_popup/my_popup.dart';
import '../../../../common/my_popup/my_popup_child.dart';




class DropDownMenu extends StatefulWidget with MyPopupChild{

  final _PopController controller = _PopController();
  @override
  State<DropDownMenu> createState() => _DropDownMenuState();

  @override
  dismiss() {
    // TODO: implement dismiss
    controller.dismiss();
  }
}

class _DropDownMenuState extends State<DropDownMenu> with SingleTickerProviderStateMixin{

  late Animation<Offset> _animation;
  late AnimationController _controller;
  
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    widget.controller._bindState(this);
    _controller = AnimationController(
      vsync: this,
      duration: Duration(milliseconds: 300),
    );
    _animation = Tween<Offset>(begin: Offset(0, -1),end: Offset.zero).animate(_controller);
    _controller.forward();
  }
  dismiss(){
    _controller?.reverse();
  }
  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _controller?.dispose();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.transparent,
      body: Container(
        padding: EdgeInsets.only(top: ScreenUtil.getStatusBarH(context) + 50),
        child: ClipRect(
          child: SlideTransition(
            position: _animation,
            child: Container(
              color: Colors.white,
              child: ListView.builder(
                padding: EdgeInsets.all(0),
                  shrinkWrap: true,
                  itemCount: 4,
                  itemExtent: 50,

                  itemBuilder: (context,index){
                    return GestureDetector(
                      behavior: HitTestBehavior.opaque,
                      onTap: (){
                        MyPopup.pop(context);
                      },
                      child: Container(
                        alignment: Alignment.center,
                        child: Text(
                          'item$index',
                        ),
                      ),
                    );
                  }
              ),
            ),
          ),
        ),
      ),
    );
  }
}

class _PopController {
  late _DropDownMenuState state;

  _bindState(_DropDownMenuState state) {
    this.state = state;
  }

  dismiss() {
    state?.dismiss();
  }
}